package com.zxwl.obs.service;

import javax.annotation.Resource;

import net.sf.json.JSONObject;

import org.springframework.stereotype.Component;

import com.zxwl.base.dao.IBaseDao;
import com.zxwl.base.service.BaseService;
import com.zxwl.common.log.ILogger;
import com.zxwl.common.log.LoggerManager;
import com.zxwl.obs.entity.HuaweiHoliday;
import com.zxwl.obs.entity.HuaweiObsUserData;
import com.zxwl.obs.entity.HuaweiTask;

@Component
public class HuaweiTaskService extends BaseService<HuaweiTask> implements IHuaweiTaskService
{
	
	private final ILogger logger = LoggerManager.getLogger(HuaweiTaskService.class);
	
	@Resource
	private IHuaweiHolidayService huaweiHolidayService;
	@Resource
	private IHuaweiObsUserDataService huaweiObsUserDataService;
	
	@Override
	@Resource
	public void setDao(IBaseDao<HuaweiTask> huaweiTaskDao)
	{
		this.dao = huaweiTaskDao;
	}

	@Override
	public void saveAll(HuaweiTask task, HuaweiHoliday holiday, HuaweiObsUserData userData)
	{
		if(null != holiday)
		{
			this.logger.info("saveAll--保存节假日！holiday："+JSONObject.fromObject(holiday));
			huaweiHolidayService.save(holiday);
		}
		if(null != task)
		{
			if(null != holiday) task.setHolidayId(holiday.getHolidayId());
			this.logger.info("saveAll--保存任务信息！task："+JSONObject.fromObject(task));
			this.dao.save(task);
		}
		if(null != userData)
		{
			if(null != task) userData.setsServiceId(task.getsServiceid());
			this.logger.info("saveAll--保存用户信息！userData："+JSONObject.fromObject(userData));
			huaweiObsUserDataService.save(userData);
		}
	}

}
